docs: warn that setIdentity()/clearIdentity() end impersonation#789
Draft
dereuromark wants to merge 1 commit into4.xfrom
Draft
docs: warn that setIdentity()/clearIdentity() end impersonation#789dereuromark wants to merge 1 commit into4.xfrom
dereuromark wants to merge 1 commit into4.xfrom
Conversation
Calling setIdentity() (and clearIdentity() / logout()) silently ends an active impersonation session because the service's clearIdentity() actively calls stopImpersonating() on impersonation-aware authenticators. This is surprising when applications use setIdentity() in beforeFilter() to eager-load associations on the active user. Add a third "Limitations" bullet to the impersonation docs with the recommended workaround (write to the request attribute directly), and add a "Replacing the current identity" section to the component docs that documents setIdentity() and links to the impersonation note.
Member
Author
|
With #788 accepted, it would superseed this PR, so draft for now again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docs/en/impersonation.mdexplaining thatsetIdentity()andclearIdentity()(and thereforelogout()) silently end impersonation, with a recommended workaround for the common "refresh active user" use case.docs/en/authentication-component.mdthat documentssetIdentity()(it wasn't documented in this file before) and links the impersonation warning.Why
The interaction is real and surprising:
AuthenticationComponent::setIdentity()calls the service'sclearIdentity()first, andAuthenticationService::clearIdentity()actively callsstopImpersonating()on anyImpersonationInterfaceauthenticator that returnstrueforisImpersonating()(AuthenticationService.php#L194).So an app pattern like
silently ends impersonation on every request where the association was missing. The recommended workaround (write to the request attribute directly) is small but isn't currently documented.
Notes
replaceIdentity()convenience method that codifies the workaround as first-class API. This docs PR stands on its own and is useful regardless of whether Add AuthenticationComponent::replaceIdentity() #788 lands; the docs example just uses the manualwithAttribute()form.